public class Interrupt{

    public static void main(String[] args){

        My m = new My();
        Thread t = new Thread(m, "Thread 007");
        t.start();

        try{
            Thread.sleep(2000);
        }catch(Exception e){
            e.printStackTrace();
        }

        // use interrupt()
        t.interrupt();

    }

}

class My implements Runnable{

    public void run(){

        try{
            for(int i = 0; i < 10; i++){
                Thread.sleep(500);
                System.out.println("Thread sleep finished --> " + i);
            }
        }catch(Exception e){
            System.out.println("thread interrupt!");
        }

    }

}